import { defineStore } from "pinia";
import requests from "../utils/requests";

const useChangePwdStore=defineStore('changePwd',{
	state:()=>({
		form:{
			oldPassword:'',
			newPassword:'',
			confirmPassword:''
		}
	}),
	actions:{
		async changePwd(){
			const res=await requests({
				url:'/base/changePwd/',
				method:'post',
				data:{
					username:uni.getStorageSync('username'),
					oldPassword:this.form.oldPassword,
					password:this.form.newPassword
				}
			})
			if (res.code===200){
				this.form.oldPassword=''
				this.form.newPassword=''
				this.form.confirmPassword=''
				uni.$u.toast('修改密码成功')
			}else{
				uni.$u.toast(`修改密码失败，${res.error}`)
			}
		}
	}
})
export default useChangePwdStore;